package com.tencreat.mall.controller.common;

import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.domain.mall.dto.WxApiUnionIdDTO;
import com.tencreat.domain.mall.vo.ResWxApiUnionIdVO;
import com.tencreat.service.mall.IWxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 微信相关接口
 * @author zixin
 * @since 2021-12-21 11:22
 */
@RestController
@RequestMapping("/mall/common/wx")
@Api(tags = "微信相关接口")
@Slf4j
public class WxApiController extends BaseController {

    @Autowired
    private IWxService wxService;

    @ApiOperation("获取微信unionId")
    @PostMapping("/union-id")
    HttpResult<ResWxApiUnionIdVO> unionId(@RequestBody @Validated WxApiUnionIdDTO dto) {
        return HttpResult.ok(wxService.getUnionId(dto));
    }


    @ApiOperation("绑定微信")
    @PostMapping("/bind-wx")
    public HttpResult<Void> bindWx(@RequestBody @Validated WxApiUnionIdDTO dto) {
        dto.setUserId(getLoginCheck().getAccountLogin().getUuid());
        wxService.bindWx(dto);
        return HttpResult.ok();
    }

}
